﻿
using System;

namespace ProjectChildhood
{
    public interface IPowerup
    {
        public string Key { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public bool Unlocked { get; set; }
        public int Price { get; set; }
        bool ShowCondition();

        void OnUnlock();
    }

    public class Powerup : IPowerup
    {
        public string Key { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public bool Unlocked { get; set; }
        public int Price { get; set; }

        private Func<Powerup, bool> m_Condition; // 解锁条件

        private Action<Powerup> m_OnUnlock;
        public void OnUnlock()
        {
            Unlocked = true;
            m_OnUnlock?.Invoke(this);
        }

        // 解锁条件
        public bool ShowCondition()
        {
            return !Unlocked && (m_Condition == null || m_Condition(this));
        }

        public Powerup WithPrice(int price)
        {
            Price = price;
            return this;
        }

        public Powerup WithTitle(string title) 
        {
            Title = title; 
            return this; 
        }

        public Powerup WithKey(string key)
        {
            Key = key;
            return this;
        }

        public Powerup WithDescribtion(string desc)
        {
            Description = desc;
            return this;
        }

        public Powerup Condition(Func<Powerup, bool> condition)
        {
            m_Condition = condition;
            return this;
        }

        public Powerup OnUnlock(Action<Powerup> onUnlock)
        {
            m_OnUnlock = onUnlock;
            return this;
        }
    }
}
